package com.dr.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dr.entity.Product;
import com.dr.entity.ProductVO;
import com.dr.entity.Producttype;
import com.dr.mapper.ProductMapper;
import com.dr.service.ProductService;

@Service // bean
@Transactional // 事务
public class ProductServiceImpl implements ProductService {
	// 注入mapper
	@Autowired
	private ProductMapper productMapper;

	/**
	 * 查询全部
	 */
	public List<Product> AllProduct(ProductVO productVO) {
		// TODO Auto-generated method stub
		return productMapper.AllProduct(productVO);
	}

	/**
	 * 查询行数
	 */
	public Integer getCount(ProductVO productVO) {
		// TODO Auto-generated method stub
		return productMapper.getCount(productVO);
	}

	/**
	 * 删除一组数据
	 */

	public int deleteProducts(String ids) { // TODO Auto-generated method stub
		return productMapper.deleteProducts(ids);
	}

	/**
	 * 单个删除
	 */
	public int deleteProduct(int id) { // TODO Auto-generated method stub return
		return productMapper.deleteProduct(id);
	}

	/**
	 * 添加
	 */
	public int insertProduct(Product p) { // TODO Auto-generated method stub
		return productMapper.insertProduct(p);
	}

	/**
	 * 修改
	 */

	public Integer updateProduct(Product p) { // TODO Auto-generated method stub
		return productMapper.updateProduct(p);
	}

	

	/**
	 * 修改是否上架
	 */
	@Override
	public Integer updateisSoldOut(int id, int isSoldOut) {
		// TODO Auto-generated method stub
		return productMapper.updateisSoldOut(id, isSoldOut);
	}

	/**
	 * 修改是否允许被删除（0不允许，1允许，默认值是1，只要下过订单就改成0）
	 */
	@Override
	public Integer updateisDel(int id, int isDel) {
		// TODO Auto-generated method stub
		return productMapper.updateisDel(id, isDel);
	}

	/**
	 * 修改是否推荐到首页（默认值是0，0不推荐，1代表推荐）
	 * @param p对象
	 * @return 数据库受影响的行数
	 */
	public Integer updateisRecommendMain(int id, int isRecommendMain) {
		// TODO Auto-generated method stub
		return productMapper.updateisRecommendMain(id, isRecommendMain);
	}

	/**
	 * 获取产品分类
	 */
	public List<Producttype> findPtype() {
		// TODO Auto-generated method stub
		return productMapper.findPtype();
	}
	/**
	 * 上传图片
	 */
	
	@Override
	public int editImg(int id, String imgMain, String imgFu) {
		// TODO Auto-generated method stub
		return productMapper.editImg(id, imgMain, imgFu);
	}

	@Override
	public List<Product> findWebIndexProduct(String name, Integer tid, Integer isRecommendMain) {
		// TODO Auto-generated method stub
		return productMapper.findWebIndexProduct(name, tid, isRecommendMain);
	}

}
